
/*

Author   : chaos

FileName : stl_ins_iter.cpp

Date     : 17/08/17 18:07:45

*/
#include <iostream>
#include <iterator>
#include <algorithm>
#include <vector>
#include <deque>
using namespace std;

template <class  T>
void print(deque<T> & pri_con)
{
    if(pri_con.empty())
        cout << "Container is empty !" << endl;
    else
    {
        typename deque<T>::iterator i;
        for(i = pri_con.begin(); i != pri_con.end(); i++)
        { cout << *i << " "; }
        cout << endl;
    }
}

int main(int argc ,char *argv[])
{

    deque<char> d1(2,'A'),d2(2,'B'),d3(2,'C'),d4(2,'D');

    cout << "Insert d2 into the back of d1's first element ..." << endl;
    copy(d2.begin() ,d2.end() ,inserter(d1,d1.begin()+1));

    print(d1);

    cout << "Insert d3 into front of d1's first element ..." << endl;
    copy(d3.begin(),d3.end() ,front_inserter(d1));

    print(d1);

    cout << "Insert d4 into d1's last element ..." << endl;
    copy(d4.begin() ,d4.end(), back_inserter(d1));

    print(d1);

    return 0;
}
